﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;


using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;
using System.Data.Entity.Infrastructure;
using System.ComponentModel.DataAnnotations;

using Projectmanagement.Entity;


namespace Projectmanagement.Utl
{
    public class DB : DbContext
    {
        public DbSet<Project> Projects { get; set; }
        public DbSet<TaskTemplate> TaskTemplates { get; set; }
        public DbSet<Task> Tasks { get; set; }
        public DbSet<Area> Areas { get; set; }
        public DbSet<TaskState> TaskStates { get; set; }
        public DbSet<TaskComment> TaskComments { get; set; }
        public DbSet<ProjectType> ProjectTypes { get; set; }
        public DbSet<Member> Members { get; set; }
        public DbSet<SimulatorConfig> SimulatorConfigs { get; set; }
        public DbSet<EmployeeRolePM> EmployeeRolePMs { get; set; }
        public DbSet<RolePM> RolePMs { get; set; }
        public DbSet<Country> Countrys { get; set; }
        public DbSet<Milestone> Milestone { get; set; }
        public DbSet<MilestoneTemplate> MilestoneTemplate { get; set; }
        public DbSet<Printing> Printing { get; set; }
        public DbSet<Equipment> Equipment { get; set; }
        public DbSet<Simultaneous> Simultaneous { get; set; }
        public DbSet<Edm> Edm { get; set; }
        public DbSet<Motorcade> Motorcade { get; set; }
        public DbSet<Construct> Construct { get; set; }
        public DbSet<Tracel> Tracel { get; set; }
        public DbSet<Chamber> Chamber { get; set; }
        public DbSet<LocationDistance> LocationDistance { get; set; }
        public DbSet<BanquetHall> BanquetHall { get; set; }
        public DbSet<City> Citys { get; set; }
        public DbSet<Customer> Customer { get; set; }
        public DbSet<TaskTrack> TaskTracks { get; set; }
        public DbSet<TaskFile> TaskFiles { get; set; }
        public DbSet<UploadFile> UploadFiles { get; set; }
        public DbSet<TaskTemplateType> TaskTemplateTypes { get; set; }
        public DbSet<SimultaneousTeacher> SimultaneousTeachers { get; set; }
        public DB(string connection = null)
        {
            // Database.SetInitializer<DB>(new DBInitializer());
            Database.SetInitializer<DB>(null);
            //if (!string.IsNullOrEmpty(connection))
            //    this.Database.Connection.ConnectionString = connection;

            this.Configuration.LazyLoadingEnabled = true;
            this.Configuration.ValidateOnSaveEnabled = false;
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
        }

        //public void Detach(object entity)
        //{
        //    ((IObjectContextAdapter)this).ObjectContext.Detach(entity);
        //}



    }

    public class DBAccount : DbContext
    {
        public DbSet<EmployeeRole> EmployeeRoles { get; set; }
        public DbSet<Role> Roles { get; set; }
        public DbSet<Department> Departments { get; set; }
        public DbSet<ExpLevel> ExpLevels { get; set; }

        public DBAccount(string connection = null)
        {
            // Database.SetInitializer<DB>(new DBInitializer());
            Database.SetInitializer<DBAccount>(null);
            //if (!string.IsNullOrEmpty(connection))
            //    this.Database.Connection.ConnectionString = connection;

            this.Configuration.LazyLoadingEnabled = true;
            this.Configuration.ValidateOnSaveEnabled = false;
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
        }
    }

    public class DBInitializer : DropCreateDatabaseIfModelChanges<DB>
    {
        protected override void Seed(DB context)
        {
            //FakeData(context);
            //context.SaveChanges();
        }

        private void FakeData(DB context)
        {

        }
    }



}